<template>
  <div id="isAtLesson">
    <van-nav-bar
      :title="title"
      left-arrow
      fixed
      @click-left="$router.back()"
    />
    <div class="lessons_wrapper" v-if="lessonList.length">
      <div class="lesson_item" @click="lessonDetails(item)" v-for="(item,index) in lessonList"
      :key="index">
        <p class="title">{{item.className}}</p>
        <p class="person">
          <i class="icon iconfont icon-icon-test"></i>
          <span>{{teacherName}}</span>
        </p>
        <p class="address">
          <i class="icon iconfont icon-mendoor13"></i>
          <span>{{item.classRoomName}}</span>
          <span>{{[item.startDate,item.endDate] | timeFilter}}</span>
          <span class="budege">{{item.status?'已上课':'未上课'}}</span>
        </p>
        <div class="number">{{item.hadMention}}/{{item.needMention}}</div>
      </div>
    </div>
    <div class="emptyList" v-else>
      <p>
        <i class="icon iconfont icon-zanwukechengeps"></i>
      </p>
      <p>暂无课程</p>
    </div>
  </div>
</template>

<script>
import { NavBar } from 'vant'
import { getFormateDate, getCookieStorage, getWeekday } from '@/assets/js/common.js'
export default {
  data () {
    return {
      title: '',
      userId: getCookieStorage('userInfo').id,
      mentionYMD: getFormateDate(new Date(), 'yyyyMMdd'),
      lessonList: [],
      teacherName: ''
    }
  },
  mounted () {
    let week = getWeekday(new Date().getDay())
    this.title = getFormateDate(new Date(), 'MM月dd日') + '（' + week + ')'
    this.getlist()
  },
  methods: {
    getlist () {
      this.$api.post('/api/mention/getTeacherMentionList', {
        userId: this.userId,
        mentionYMD: Number(this.mentionYMD)
      }).then(res => {
        if (res.code === 0) {
          this.lessonList = res.data.teacherMentionList
          if (res.data.mdTeacherEntity && res.data.mdTeacherEntity.name) {
            this.teacherName = res.data.mdTeacherEntity.name
          }
          console.log(this.lessonList)
        }
      })
    },
    lessonDetails (item) {
      this.$router.push({path: '/lessonDetails', query: {id: item.id}})
    }
  },
  components: {
    NavBar
  }
}
</script>

<style lang="scss" scoped>
#isAtLesson {
  height: 100%;
  background-color: #f9f9f9;
  .time_header {
    height: .42rem;
    line-height: .42rem;
    text-align: center;
    font-size: 16px;
    background: #fff;
    margin-bottom: .08rem;
  }
  .emptyList {
    background: #fff;
    padding: .2rem 0;
    padding-top: .5rem;
    p {
      text-align: center;
      font-size: 16px;
      color: #ccc;
      .icon {
        font-size: 100px;
      }
    }
  }
  .lessons_wrapper {
    position: fixed;
    top: .46rem;
    bottom: 0;
    width: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    .lesson_item {
      padding: .1rem 0;
      border-bottom: .5px solid #ececec;
      position: relative;
      // &:last-child {
      //   border: none;
      // }
      p {
        margin: 0;
        font-size: 14px;
        padding: .05rem .12rem;
        .icon {
          color: orange;
        }
        .budege {
          display: inline-block;
          height: 16px;
          background: #2196f3;
          border-radius: 8px;
          color: #fff;
          font-size: 12px;
          padding: 0 .05rem;
        }
      }
      .title {
        font-size: 16px;
      }
      .number {
        position: absolute;
        top: 50%;
        right: .2rem;
        transform: translateY(-50%);
      }
    }
  }
}
</style>
